package com.situ.mall.controller.front;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.common.ServerResponse;
import com.situ.mall.entity.Cart;
import com.situ.mall.entity.User;
import com.situ.mall.service.ICartService;

@Controller
@RequestMapping("/cart")
public class FrontCartController {
	
	@Autowired
	private ICartService cartService;
	
	@RequestMapping("/insert.shtml")
	@ResponseBody
	public ServerResponse insert(Integer productId, Integer num, HttpSession session) {
		return cartService.insert(productId,num,session);
	}
	
	@RequestMapping("/getCartListPage.shtml")
	public String getCartListPage(HttpSession session,Model model) {
		User user = (User) session.getAttribute("user");
		List<Cart> list = cartService.selectByUserId(user.getId());
		model.addAttribute("list", list);
		
		return "cart_list";
	}
	
	@RequestMapping("/updateCheckStatus.shtml")
	@ResponseBody
	public ServerResponse updateCheckStatus(Integer cartId,Integer checked) {
		return cartService.updateCheckStatus(cartId,checked);
	}
	
	@RequestMapping("/updateQuantity.shtml")
	@ResponseBody
	public ServerResponse updateQuantity(Integer cartId,Integer num) {
		return cartService.updateQuantity(cartId,num);
	}
	
	@RequestMapping("/deleteById.shtml")
	@ResponseBody
	public ServerResponse deleteById(Integer cartId) {
		return cartService.deleteById(cartId);
	}
	
	
	@RequestMapping("/updateCheckedStatusByUserId.shtml")
	@ResponseBody
	public ServerResponse updateCheckedStatusByUserId(Integer userId) {
		return cartService.updateCheckedStatusByUserId(userId);
	}

}
